#include <QProcess>
#include <QMessageBox>

#include "formsystemsetting.h"
#include "ui_formsystemsetting.h"
#include "sysinfo.h"

#include <QDebug>

FormSystemSetting::FormSystemSetting(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::FormSystemSetting)
{
    ui->setupUi(this);
    setWindowFlags(windowFlags() | Qt::Dialog);
    setWindowModality(Qt::ApplicationModal);
    setAttribute(Qt::WA_DeleteOnClose);

    Sysinfo sysinfo;
    ui->horizontalSliderBackLight->setValue(sysinfo.getBackLight());

    qDebug() << "[FormSystemSetting] \t Constructor";
}

FormSystemSetting::~FormSystemSetting()
{
    delete ui;

    qDebug() << "[FormSystemSetting] \t Destructor";
}


void FormSystemSetting::on_pushButtonSystemSettingReturn_clicked()
{
    this->close();
}

void FormSystemSetting::on_pushButtonReboot_clicked()
{
    int ret = QMessageBox::question(this, tr(" "), tr("是否重启？"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);

    if (ret == QMessageBox::Yes)
    {
        QProcess p(nullptr);
        p.start("reboot");
        p.waitForStarted();
        p.waitForFinished();
        p.close();
    }
}

void FormSystemSetting::on_horizontalSliderBackLight_valueChanged(int value)
{
    Sysinfo sysinfo;
    sysinfo.setBackLight(value);

    ui->labelBLLevelValue->setNum(value);
}
